var express = require('express'), http = require('http'), path = require('path');

var static = require('serve-static');
var app = express();
var router = express.Router();
app.use(static(__dirname));
app.set('port', process.env.PORT || 8080);
app.set('host', '127.0.0.1');

router.route('/').get(function(req, res){res.redirect("/JQuery.html")});
router.route('/routetest').get(function(req, res){res.redirect("http//google.com")});

router.route('/rss').get(function(req, res){
	console.log("rss data requested");
	var feed = "http://news.sbs.co.kr/news/SectionRssFeed.do?sectionId=02&plink=RSSREADER";
	http.get(feed, function(httpres){
		var rss_res = "";
		httpres.on('data', function (chunk){
			rss_res += chunk;
		});
		httpres.on('end', function (){
			res.send(rss_res);
			console.log("rss response completed");
			res.end();
		});
	});
});

app.use('/', router);
	
http.createServer(app).listen(app.get('port'), app.get('host'), () => {
	console.log('Express server running at ' + app.get('port') + app.get('host'));
});
